<template>
  <div class="businessUnit">
    <topBar :title="title"></topBar>
    <div class="connet">
      <div class="text">
        <div>
          <div class="cont">
            <div class="square"></div>
            <div class="value">{{ strList[0] }}</div>
          </div>
          <p><span class="circle"></span>{{ strList[1] }}</p>
          <p><span class="circle"></span>{{ strList[2] }}</p>
          <p><span class="circle"></span>{{ strList[3] }}</p>
        </div>
      </div>
      <div class="table">
        <el-table
          :data="tableData"
          border
          :cell-style="cellStyle"
          :header-cell-style="{
            background: '#C00000',
            color: '#ffffff',
            padding: '0',
            height: '26px',
          }"
        >
          <el-table-column
            label="经营单元"
            prop="areaName"
            align="center"
          ></el-table-column>
          <el-table-column
            :label="headerList[1]"
            prop="lastYearT0"
            align="center"
          ></el-table-column>
          <el-table-column
            :label="headerList[2]"
            prop="thisYearLjIncome"
            align="center"
          ></el-table-column>
          <el-table-column
              label="保有率"
              align="center"
              prop="rate"
          >
            <template slot-scope="scope">
                <div v-if="scope.row.rate">
                  {{ scope.row.rate + "%" }}
                </div>
                <div v-else></div>
            </template>
          </el-table-column>
          <el-table-column
            width="120"
            label="排名"
            prop="orderSeq"
            align="center"
          >
          <template slot-scope="scope">
                <div >
                  {{ scope.row.orderSeq || '-' }}
                </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import topBar from "./topBar";
import { penetration } from "@/api/codeIncome/analysis";
export default {
  name: "businessUnit",
  components: {
    topBar,
  },
  data() {
    return {
      title: "码号收入 – 经营单元存量收入保有率",
      acctMonth: "",
      monthFrom: "",
      strList: [],
      headerList: [],
      tableData: [],
    };
  },
  props: {
    searchData: {
      type: Object,
      default: {},
    },
  },
  watch: {
    searchData: {
      handler(newName) {
          this.getData();
      },
      deep: true,
    },
  },
  created() {},
  mounted() {
    this.getData();
  },
  methods: {
    cellStyle({row, column, rowIndex, columnIndex}) {
        if (row.mhColorSign == "MH_UP_0" && column.label == '保有率') {
            return "background: #5A8AC6;padding:0;color:black"
        } else if (row.mhColorSign == "MH_UP_1" && column.label == '保有率') {
            return "background: #7BA1D2;padding:0;color:black"
        } else if (row.mhColorSign == 'MH_UP_2' && column.label == '保有率') {
            return "background: #D9E4F3;padding:0;color:black"
        } else if (row.mhColorSign == 'MH_DOWN_0' && column.label == '保有率') {
            return "background: #F8696B;padding:0;color:black"
        } else if (row.mhColorSign == 'MH_DOWN_1' && column.label == '保有率') {
            return "background: #F98E95;padding:0;color:black"
        } else if (row.mhColorSign == 'MH_DOWN_2' && column.label == '保有率') {
            return "background: #FABCBE;padding:0;color:black"
        }
        if (row.areaName == '杭州') {
            return 'font-weight:bold;color:black;padding:0;'
        }
        return "color:black;padding:0"
    },
    // 经营单元存量收入保有率
    getData() {
      penetration({
        acctMonth: this.searchData.acctMonth,
        // areaId: this.searchData.areaId,
      }).then((res) => {
        if (res.code == 200) {
          this.acctMonth = res.data.name;
          this.headerList = res.data.nameList
          this.strList = res.data.strList[0].datas
          this.tableData = res.data.data;
        }
      });
    },
  },
};
</script>

<style scoped>
.businessUnit {
  box-sizing: border-box;
  padding: 20px;
  box-shadow: 0px 0px 10px 1px rgb(0 0 0 / 15%);
}
</style>

<style scoped lang="scss">
.businessUnit {
  margin-top: 20px;
}
.connet {
  box-sizing: border-box;
  padding: 0 20px;
  margin-top: 10px;
  .text {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    .cont {
      font-size: 24px;
      line-height: 44px;
      display: flex;
    }
    .square {
      margin-top: 15px;
      margin-right: 15px;
      width: 10px;
      height: 10px;
      background: #c00000;
      transform: rotate(45deg);
    }
    .value {
      flex: 1;
      flex-wrap: wrap;
    }
    p {
      display: flex;
      align-items: center;
      padding-left: 40px;
      font-size: 20px;
      .circle {
        width: 4px;
        height: 4px;
        background-color: #c0504d;
        border-radius: 50%;
        display: inline-block;
        margin-right: 10px;
      }
    }
  }
  .table {
      width: 100%;
  }
  /deep/ .el-table {
    width: 100%;
  }
}
</style>
